package de.sendorian.app.forumArchive.script;


import static de.sendorian.app.forumArchive.matcher.ForumMatcher.*;

import java.util.LinkedHashSet;
import java.util.Set;

import org.joda.time.DateTime;
import org.junit.BeforeClass;
import org.junit.Test;

import de.sendorian.app.forumArchive.Compressor;
import de.sendorian.app.forumArchive.Config;
import de.sendorian.app.forumArchive.repository.ForumRepository;
import de.sendorian.db.DAO;

public class ActionScripts {

	@BeforeClass
	public static void configureLogging() {
		Config.configureLogging();
	}

	@Test
	public void compressImagesInFolders() {
		Config config = Config.get();
		String downloadDir = config.getDownloadDir();
		Set<String> folders = new LinkedHashSet<String>();
		folders.add(downloadDir + "/Objects and Textures (Fantasy)/For hes a lumberjack");
		new Compressor().compressImagesInFolders(folders);
	}

	@Test
	public void compressImagesInTopicsByDate() {
		doCompressImagesInTopicsByDate(2009, 10, 1);
	}

	@Test
	public void compressAllImagesInTopics() {
		doCompressImagesInTopicsByDate(2000, 1, 1);
	}

	private void doCompressImagesInTopicsByDate(int year, int month, int day) {
		DateTime start = new DateTime().withDate(year, month, day);
		new Compressor().compressImages(new ForumRepository().findAll(),
		    matchesDateIntervalUntilNow(start));
		DAO.shutdownDatabase();
	}

}
